package com.black.service.config;

import com.black.utils.encrypt.sm4.SM4Util;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
import org.aspectj.lang.annotation.Pointcut;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.autoconfigure.data.redis.RedisProperties;
import org.springframework.context.annotation.Configuration;

@Aspect
@Configuration
public class RedisConfig {

    private final RedisProperties redisProperties;

    @Value("${spring.redis.password}")
    private String password;

    public RedisConfig(RedisProperties redisProperties) {
        this.redisProperties = redisProperties;
    }

    @Pointcut("execution(* org.springframework.boot.autoconfigure.data.redis.RedisProperties.getPassword())")
    public void getRedisConnectionPwd() {
    }

    @Before("getRedisConnectionPwd()")
    public void setRedisProperties() {
        redisProperties.setPassword(SM4Util.decryptData_CBC(this.password));
    }
}
